package cn.sinjet.carassist;

import java.util.ArrayList;
import java.util.List;

import com.mgroup.wazehelper.R;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ListView;
import android.widget.RadioButton;
import cn.sinjet.adapter.MyPidListAdapter;
import cn.sinjet.entity.PID;
import cn.sinjet.model.carsystem.CarModel;
import cn.sinjet.viewmodel.IUpdateUI;
import cn.sinjet.viewmodel.PageDefine;
import cn.sinjet.viewmodel.ViewModel;

public class FastDetectActivity extends MyActivity implements OnClickListener,IUpdateUI{
	SinjetApplication app;
	ListView mPidView;
	MyPidListAdapter mAdapterPidList;
	List<PID> mPidDataList = new ArrayList<PID>();
	RadioButton vShowAll;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		app = SinjetApplication.getInstance();
		super.setMyContentView(R.layout.activity_fast_detect);
		vShowAll = (RadioButton)mViewRoot.findViewById(R.id.display_all);
		vShowAll.setOnClickListener(this);
		vShowAll.setChecked(CarModel.getInstance().devModule.getObdData().isShowAll());
		mPidView = (ListView) mViewRoot.findViewById(R.id.fast_detect_car_listview_pid);
		mAdapterPidList = new MyPidListAdapter(this, mPidDataList);
		mPidView.setAdapter(mAdapterPidList);
		
		initData();
	}
	
	private void initData(){
		
       refreshPidList();		
//		m_cbShowAll.setChecked(mApp.getSinjetModel().getSettingsModule().isFastDetectionShowAll());
//		registerReceiver(m_uiUpdateReceiver, makeUiUpdateIntentFilter());
	}
	
	private void refreshPidList(){
		CarModel.getInstance().devModule.getObdData().showPid();
		List<PID> pidListData = new ArrayList<PID>();
		pidListData.addAll(CarModel.getInstance().devModule.getObdData().getPidDataList());
		mAdapterPidList.setListData(pidListData);
	}
	
	/*public void refreshPidList()
	{
		mApp.getSinjetModel().getCarInfoModule().showPid();

		List<PID> pidListData = new ArrayList<PID>();
		pidListData.addAll(mApp.getSinjetModel().getCarInfoModule().getPidListData());
		 
		m_adapterPidList.setListData(pidListData);
	}*/
	
	@Override
	public void onClick(View view) {
		// TODO Auto-generated method stub
		switch(view.getId()){
		case R.id.err_query_back:
			ViewModel.getIns().jumpPage(PageDefine.PAGE_HOME);
			break;
		case R.id.display_all:
			CarModel.getInstance().devModule.getObdData().onClkShowAll();
			vShowAll.setChecked(CarModel.getInstance().devModule.getObdData().isShowAll());
			refreshPidList();
			break;
		}
	}
	
	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		ViewModel.getIns().onActivityResume(this, PageDefine.PAGE_FAST_DECTECT, this);
	}
	@Override
	public void updateUI(Bundle data) {
		// TODO Auto-generated method stub
		super.updateUI(data);
		if(data.getInt("id",-1) == R.id.fast_detect_car_listview_pid){
			Log.d("BT", "update fuck pid List");
			refreshPidList();
		}
	}
	

}
